package com.study.talk.util;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author thor
 * @description:
 * @date 2024/10/14 19:19
 */
public class AppExecutor {
    private final String TAG = "AppExecutor";
    private final ThreadPoolExecutor fileIO;
    private final ThreadPoolExecutor netIO;
    private final ScheduledExecutorService scheduleIO;
    private final Handler handler;
    private static AppExecutor instance;

    private AppExecutor() {
        fileIO = new ThreadPoolExecutor(3,6,10, TimeUnit.SECONDS,new LinkedBlockingDeque<>());
        netIO = new ThreadPoolExecutor(3,6,60, TimeUnit.SECONDS,new LinkedBlockingDeque<>());
        scheduleIO = Executors.newScheduledThreadPool(10);
        handler = new Handler(Looper.getMainLooper());
    }

    public ThreadPoolExecutor FILE_IO(){
        return this.fileIO;
    }

    public ThreadPoolExecutor NET_IO(){
        return this.netIO;
    }

    public Executor SCHEDULE_IO(){
        return this.scheduleIO;
    }

    public Handler MAIN_HANDLER(){
        return this.handler;
    }

    synchronized public static AppExecutor getInstance(){
         if (instance == null) return new AppExecutor();
         else return instance;
    }

}
